<?php
/**
 * @file
 * Download Monitor - Allows you to trace file downloads. Just place the direct link
 * to the file on the web, and specify the extensions of files you want to trace in the GUI.
 * It creates interactive chart and records downloads for today, yesterday, this week,
 * last week, this month, last month and total.
 * Requires writable .htaccess file of Apache Web server in Joomla root folder.
 * @package download-monitor
 * @version 1.0
 * @revision @REVISION@
 * @license http://www.gnu.org/licenses/gpl-3.0.txt     GNU General Public License v3
 * @copyright (C) 2012 by CodeGravity.com - All rights reserved!
 * @website http://www.codegravity.com
 */
?>
<table id="myTable" class="tablesorter">
    <thead>
    <tr>
        <th>Path</th>
        <th>Today</th>
        <th>Yesterday</th>
        <th>This Week</th>
        <th>Last Week</th>
        <th>This Month</th>
        <th>Last Month</th>
        <th>Total</th>
    </tr>
    </thead>
    <tbody>
    <?php
    if (@$filepathar)
        foreach($filepathar as $filepath)
        {
            $did = $filepath[0];

            $filepathquery_curr = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate='%s' and did='%d'", mysql_escape_string($currdate), (int) $did);
            $db->setQuery($filepathquery_curr);
            $count_curr_dt  = $db->loadResult();

            $filepathquery_yes = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate='%s' and did='%d'", mysql_escape_string($yesterday), (int) $did);
            $db->setQuery($filepathquery_yes);
            $count_yes_dt  = $db->loadResult();

            $filepathquery_cw = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate>'%s' and did='%d'", mysql_escape_string($weekday), (int) $did);
            $db->setQuery($filepathquery_cw);
            $count_cw_dt  = $db->loadResult();

            $filepathquery_lw = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate<='%s' and ddate>'%s' and did='%d'", mysql_escape_string($weekday), mysql_escape_string($lweekday), (int) $did);
            $db->setQuery($filepathquery_lw);
            $count_lw_dt  = $db->loadResult();

            $filepathquery_cm = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate>='%s' and did='%d'", mysql_escape_string($currmonthday), (int) $did);
            $db->setQuery($filepathquery_cm);
            $count_cm_dt  = $db->loadResult();

            $filepathquery_lm = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where ddate>='%s' and ddate<'%s' and did='%d'", mysql_escape_string($lastmonth), mysql_escape_string($currmonthday), (int) $did);
            $db->setQuery($filepathquery_lm);
            $count_lm_dt  = $db->loadResult();

            $filepathquery_tot = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where did='%d'", (int) $did);
            $db->setQuery($filepathquery_tot);
            $count_tot_dt  = $db->loadResult();
            ?>

        <tr>
            <td><?php echo $filepath[1];?></td>
            <td><?php echo $count_curr_dt;?></td>
            <td><?php echo $count_yes_dt;?></td>
            <td><?php echo $count_cw_dt;?></td>
            <td><?php echo $count_lw_dt;?></td>
            <td><?php echo $count_cm_dt;?></td>
            <td><?php echo $count_lm_dt;?></td>
            <td><?php echo $count_tot_dt;?></td>
        </tr>
            <?php
        }
    ?>
    </tbody>

</table>
